package cn.succy.spider;

import java.io.IOException;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import cn.succy.spider.bean.Girl;
import cn.succy.spider.util.DownLoader;
import cn.succy.spider.util.UrlUtil;

public class Spider {

	public static void main(String[] args) {
		String urlStr = "https://mm.taobao.com/tstar/search/tstar_model.do?_input_charset=utf-8";
		DownLoader d = new DownLoader();
		try {
			String content = UrlUtil.getUrlContent(urlStr, "gb2312");
			// System.out.println(content);
			List<Girl> girls = UrlUtil.JSONParser(content);
			// System.out.println(girls);
			for (Girl girl : girls) {
				String linkUrl = girl.getLinkUrl();

				String result = UrlUtil.getUrlContent(linkUrl,"gb2312");
				if("".equals(result)||result==null)
					continue ;
				Document doc = Jsoup.parse(result);
				Element element = doc.getElementById("J_ScaleImg");
				Elements eles = element.select("p>img[src]");
				for (Element e : eles) {
					String attr = e.attr("src");
					girl.getPics().add(attr);
				}
				
				// 初始化下载器的参数
				d.init(girl, "I:/tnl/imgs/");
				d.download();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
